[Entwickler] Shunting-yard

Keiner hat dran geglaubt, doch es ist passiert, WBB Support ist auf 6.2.
Neuer Shop von Pur Digital, ich hoffe es funktioniert alles so wie es soll.
Habe extra kein Update gemacht, da ich so viel besser alten Schrott losgeworden bin.
  • Diese Erweiterung für die WoltLab Suite 5.2+ erweitert selbige um eine Implementation des Shunting-yard-Algorithmus, mit dessen Hilfe sich mathematische Operationen (z.B. aus einer Option heraus) ohne Nutzung potenziell gefährlicher PHP-Funktionen ausführen lassen.

    Nutzungsbeispiele:

    PHP

    Code
    require_once(WCF_DIR . 'lib/system/api/php-shunting-yard/autoload.php');@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@$equation = '3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3';@@@WCF_PRE_LINEBREAK@@@$result = \RR\Shunt\Parser::parse($equation);@@@WCF_PRE_LINEBREAK@@@echo $result; // 3.0001220703125

    PHP

    Code
    require_once(WCF_DIR . 'lib/system/api/php-shunting-yard/autoload.php');@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@$string = 'max(%x * 0.1 + 0.35, 2000)';@@@WCF_PRE_LINEBREAK@@@$string = str_replace('%x', 3434.133, $string);@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@$ctx = new \RR\Shunt\Context();@@@WCF_PRE_LINEBREAK@@@$allowedFunctions = ['ceil', 'exp', 'floor', 'fmod', 'max', 'min', 'pow']; // erlaubte PHP-Funktionen@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@foreach ($allowedFunctions as $fn) {@@@WCF_PRE_LINEBREAK@@@    if (str_contains($string, $fn . '(')) {@@@WCF_PRE_LINEBREAK@@@        $ctx->def($fn);@@@WCF_PRE_LINEBREAK@@@    }@@@WCF_PRE_LINEBREAK@@@}@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@$result = \RR\Shunt\Parser::parse($string, $ctx);@@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@echo $result; // 2000
    Alles anzeigen

    Quelle: https://pluginstore.woltlab.com/file/7071-entw…-shunting-yard/

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!